<?php
namespace app\decorate\controller;
use app\AdminRest;
use app\PluginManager;
use think\App;
use think\facade\Db;
use think\Request;
use app\decorate\model\AdminMaster as master_model;

class AdminMaster extends AdminRest{
    protected $model;
    protected $app;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->app= $app;
        $this->model = new master_model();

    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:大师团队列表
     */
    public function masterList(){
        $input = $this->_param;
        $dis   = [];
        if(!empty($input['name'])){
            $dis[] = ['e.nickName','like','%\\'. longbing_filterEmoji( $input['name'] ).'%'];
            $dis[] = ['b.name','like','%\\'. longbing_filterEmoji( $input['name'] ) .'%'];
        }
        //删除不是员工的数据
        $where['c.is_staff'] = 0;
        $where['a.uniacid'] = $this->_uniacid;
        $this->model->masterdelUser($where);
        $data  = $this->model->masterList(['a.uniacid'=>$this->_uniacid],$input['limit'],$dis);
        return $this->success($data);
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:添加大师团队
     */
    public function masterAdd(){
        $input = $this->_input;
        $input['uniacid'] = $this->_uniacid;
        $res   = $this->model->masterAdd($input);
        return $this->success($res);
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:59
     * @return \think\Response
     * descption:编辑|回显大师团队
     */
    public function masterUpdate(){
        $input = $this->_input;
        if(count($input)>1){
            $data = $this->model->masterUpdate(['id'=>$input['id']],$input);
        }else{
            $data = $this->model->masterInfo(['id'=>$input['id']]);
        }
        return $this->success($data);
    }


    /**
     * User: chenniang
     * Date: 2019-10-24 16:57
     * @return \think\Response
     * descption:删除大师团队
     */
    public function masterDel(){
        $input = $this->_input;
        $res   = $this->model->masterDel(['id'=>$input['id']]);
        return $this->success($res);
    }

    /**
     * User: chenniang
     * Date: 2019-10-24 16:58
     * @return void
     * descption:选择员工
     */

    public function selectStaff(){
        $staff_id = $this->model->getStaffId(['uniacid'=>$this->_uniacid]);
        $dis[] = ['a.uniacid','=',$this->_uniacid];
        $dis[] = ['a.is_staff','=',1];
//        $dis[] = ['a.name','<>',''];
        $dis[] = ['a.fans_id','not in',$staff_id];
        $data = Db::name('longbing_card_user_info')
            ->alias('a')
            ->leftJoin('longbing_card_job b','a.job_id = b.id')
            ->leftJoin('longbing_card_user c','c.id = a.fans_id')
            ->where($dis)
            ->field("a.fans_id, concat(IF(a.name = '',c.nickName,a.name),'-',ifnull(b.name,'暂无职位')) as name")
            ->group('a.fans_id')
            ->select()
            ->toArray();

        return $this->success($data);
    }








}
